package com.nxk.modules.content.web;

import com.nxk.modules.content.entity.ConHonor;
import com.nxk.modules.content.service.ConHonorService;
import com.nxk.modules.exception.ResultEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/a/content/honor")
public class ConHonorController {
    
    
    @Autowired
    private ConHonorService conHonorService;


    /**
     * 保存数据接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:edit")
    @PutMapping("/save")
    public ResultEntity save(@Validated ConHonor conHonor) {
        boolean save = conHonorService.save(conHonor);
        return save ? ResultEntity.success(conHonorService.getById(conHonor.getId())) : ResultEntity.fail();
    }


    /**
     * 更新数据接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:edit")
    @PostMapping("/update")
    public ResultEntity update(@Validated ConHonor conHonor) {
        boolean save = conHonorService.save(conHonor);
        return save ? ResultEntity.success(conHonorService.getById(conHonor.getId())) : ResultEntity.fail();
    }


    /**
     * 修改数据状态接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:edit")
    @PostMapping("/updateStatus")
    public ResultEntity updateStatus(ConHonor conHonor) {
        boolean save = conHonorService.save(conHonor);
        return save ? ResultEntity.success(conHonorService.getById(conHonor.getId())) : ResultEntity.fail();
    }


    /**
     * 根据id获取单条数据接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:view")
    @GetMapping("/get")
    public ResultEntity get(ConHonor conHonor) {
        return ResultEntity.success(conHonorService.getById(conHonor.getId()));
    }


    /**
     * 查询分页数据接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:view")
    @PostMapping("list")
    public ResultEntity list(ConHonor conHonor) {
        return ResultEntity.success(conHonorService.page(conHonor));
    }

    /**
     * 根据id物理删除数据接口
     *
     * @param conHonor
     * @return
     */
    @RequiresPermissions("content:honor:edit")
    @DeleteMapping("delete")
    public ResultEntity delete(ConHonor conHonor) {
        boolean delete = conHonorService.deleteById(conHonor.getId());
        return delete ? ResultEntity.success() : ResultEntity.fail();
    }
    
}
